<?php
namespace Admin\Controller;
use Think\Controller;
class ShopController extends Controller 
{
	/*商品首页*/
    public function index()
    {
		if($_GET['area']){
			header("Content-type: text/html; charset=utf-8");
			$area=M('area')->select();
			//print_r($_GET['area']);
			$shopModel = M('Shop');
			$shop['apply'] = 1;
			$shop['isApply'] = 1;
			//$plate=$_GET['area'];
			$plate = iconv("gb2312","utf-8",$_GET['area']);
			
			$shop['area']=$plate;
			$shops['apply']=1;
			$shops['isApply']=1;
			$shops['photo1']=array('neq','');
			
			
			$count      = $shopModel->where($shop)->count();
			$Page       = new \Think\Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$show       = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list = $shopModel->where($shop)->limit($Page->firstRow.','.$Page->listRows)->select();
			$this->assign('list',$list);// 赋值数据集
			$this->assign('page',$show);// 赋值分页输出
			//var_dump($list);exit();
			//where(array('shop_id'=>array('in','2002,1999,1998,1997'))->
			$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
			$this->assign('guding',$guding);
			$hot_shop=$shopModel->where($shops)->order('shop_id desc')->limit(3)->select();
			
			$this->assign('area',$area);
			$this->assign('hot_shop',$hot_shop);
			$this->display(); // 输出模板
			
			
		}else{
			$area=M('area')->select();
			
			$shopModel = M('Shop');
			$shop['apply'] = 1;
			$shop['isApply'] = 1;
			
			
			$shops['apply']=1;
			$shops['isApply']=1;
			$shops['photo1']=array('neq','');
			
			$count      = $shopModel->where($shop)->count();
			$Page       = new \Think\Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$show       = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list = $shopModel->where($shop)->limit($Page->firstRow.','.$Page->listRows)->select();
			$this->assign('list',$list);// 赋值数据集
			$this->assign('page',$show);// 赋值分页输出
			//var_dump($list);exit();
			//where(array('shop_id'=>array('in','2002,1999,1998,1997'))->
			$hot_shop=$shopModel->where($shops)->order('shop_id desc')->limit(3)->select();
			$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
			$this->assign('guding',$guding);
			$this->assign('area',$area);
			$this->assign('hot_shop',$hot_shop);
			$this->display(); // 输出模板
			
		}
		
    }

    /*商品首页*/
    public function shop_more($id)
    {
		if($_GET['area']){
			$arr['shop_id']	= $id;
			header("Content-type: text/html; charset=utf-8");
			$area=M('area')->select();
			$shopModel = M('goods');
			
			$plate = iconv("gb2312","utf-8",$_GET['area']);
			
			$arr['area']=$plate;
			
			$count      = $shopModel->where($arr)->count();
			$Page       = new \Think\Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$show       = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list = $shopModel->where($arr)->limit($Page->firstRow.','.$Page->listRows)->select();
			$this->assign('list',$list);// 赋值数据集
			$this->assign('page',$show);// 赋值分页输出
			//var_dump($list);exit();
			$this->assign('area',$area);
			$this->display(); // 输出模板
			
			
		}else{
			$arr['shop_id']	= $id;

			$area=M('area')->select();
			$shopModel = M('goods');
			$count      = $shopModel->where($arr)->count();
			$Page       = new \Think\Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$show       = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list = $shopModel->where($arr)->limit($Page->firstRow.','.$Page->listRows)->select();
			$this->assign('list',$list);// 赋值数据集
			$this->assign('page',$show);// 赋值分页输出
			//var_dump($list);exit();
			$this->assign('area',$area);
			$this->display(); // 输出模板
		}
    }

    /*商品详情*/
    public function goods_more($id)
    {
    	$arr['goods_id']	= $id;

    	$goodsModel = M('goods');
        $res      = $goodsModel->where($arr)->select();

        $shop['shop_id'] = $res[0]['shop_id'];
        $shopModel = M('shop');
        $shopRes      = $shopModel->where($shop)->select();

        $class['class_id'] = $res[0]['class_id'];
        $goodsRes      = $goodsModel->where($class)->limit(3)->select();
        //var_dump($goodsRes);exit();
              
        $this->assign('res',$res);
        $this->assign('shopRes',$shopRes);
        $this->assign('goodsRes',$goodsRes);

        $this->display(); // 输出模板
    }

/*     public function type($id)
    {
		//var_dump($type);
        /*$class['name'] = $type;
        $classModel = M('class');
        $classRes      = $classModel->where($class)->select();

        $goods['class_id'] = $id;
        $goodsModel = M('goods');

        $count      = $goodsModel->where($goods)->count();
        $Page       = new \Think\Page($count,25);
        $show       = $Page->show();
        $list = $goodsModel->where($goods)->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);
        $this->assign('page',$show);

        $this->display();
    } */

   public function type($id)
    {	
		if($_GET['area']){
			
			$shopModel = M('Shop');
			$area=M('area')->select();
			$shops['apply']=1;
			$shops['isApply']=1;
			$shops['photo1']=array('neq','');
			$id=$_GET['id'];
			header("Content-type: text/html; charset=utf-8");
			$plate = iconv("gb2312","utf-8",$_GET['area']);
			$shop['area']=$plate;
			
			//var_dump($list);exit();
			//where(array('shop_id'=>array('in','2002,1999,1998,1997'))->
			$hot_shop=$shopModel->where($shops)->order('shop_id desc')->limit(3)->select();
			
			$this->assign('hot_shop',$hot_shop);
			$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
			$this->assign('guding',$guding);
			
			
			$goods['class_id'] = $id;
			$classModel = M('class');
			$goodsRes      = $classModel->where($goods)->find();
			$shop['type'] = $goodsRes['name'];
			$shopModel = M('shop');
			$count      = $shopModel->where($shop)->count();
			$Page       = new \Think\Page($count,25);
			$show       = $Page->show();
			$list = $shopModel->where($shop)->limit($Page->firstRow.','.$Page->listRows)->select();
			$this->assign('list',$list);
			$this->assign('page',$show);
			$this->assign('id',$id);
			$this->assign('area',$area);
			$this->display();
		}else{
			$shopModel = M('Shop');
			$area=M('area')->select();
			$shops['apply']=1;
			$shops['isApply']=1;
			$shops['photo1']=array('neq','');
			$id=$_GET['id'];
			
			//var_dump($list);exit();
			//where(array('shop_id'=>array('in','2002,1999,1998,1997'))->
			$hot_shop=$shopModel->where($shops)->order('shop_id desc')->limit(3)->select();
			
			$this->assign('hot_shop',$hot_shop);
			$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
			$this->assign('guding',$guding);
			
			
			$goods['class_id'] = $id;
			$classModel = M('class');
			$goodsRes      = $classModel->where($goods)->find();
			$shop['type'] = $goodsRes['name'];
			$shopModel = M('shop');
			$count      = $shopModel->where($shop)->count();
			$Page       = new \Think\Page($count,25);
			$show       = $Page->show();
			$list = $shopModel->where($shop)->limit($Page->firstRow.','.$Page->listRows)->select();
			$this->assign('list',$list);
			$this->assign('page',$show);
			$this->assign('id',$id);
			$this->assign('area',$area);
			$this->display();
			
			
		}
		
		
    }

    public function sousuo()
    {
		$area=M('area')->select();
		$this->assign('area',$area);
		
		$class=M('class')->field('name')->select();
		$types='';
		foreach($class as $v){
			$types.=$v['name'].',';
		}
		
		$name=I('get.name');
		
		if(strpos($types, $name) !== false){
				$shopModel = M('Shop');
				if($_GET['id']){
					$shopModel = M('Shop');
				
					$shops['apply']=1;
					$shops['isApply']=1;
					$shops['photo1']=array('neq','');
					
					//var_dump($list);exit();
					//where(array('shop_id'=>array('in','2002,1999,1998,1997'))->
					$hot_shop=$shopModel->where($shops)->order('shop_id desc')->limit(3)->select();
					
					$this->assign('hot_shop',$hot_shop);
					
					
					$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
					$this->assign('guding',$guding);
					
					
					$shopModel=M('shop');
					$shop['type']=array('like',"%$name%");
					$are=M('area')->where(array('area_id'=>$_GET['id']))->find();
					$shop['id']=$are['name'];
					$res = $shopModel->where($shop)->select();
				if($res){
					import('ORG.Util.Page');// 导入分页类
					$count=count($res);//得到数组元素个数
					$Page= new \Think\Page($count,25);
					//$Page= new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
					$newarray_1 = array_slice($res,$Page->firstRow,$Page->listRows);
					$show= $Page->show();// 分页显示输出?
					$name=$_GET['name'];
					$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
					$this->assign('guding',$guding);
					$this->assign('name',$name);
					$this->assign("list",$newarray_1);
					$this->assign('page',$show);// 赋值分页输出
					$this->display();
				}else{
					$type['type']=$name;
					$typeRes = $shopModel->where($type)->select();
					import('ORG.Util.Page');// 导入分页类
					$count=count($typeRes);//得到数组元素个数
					$Page= new \Think\Page($count,25);
					//$Page= new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
					$newarray_1 = array_slice($typeRes,$Page->firstRow,$Page->listRows);
					$show= $Page->show();// 分页显示输出?
					$name=$_GET['name'];
					$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
					$this->assign('guding',$guding);
					$this->assign('name',$name);
					$this->assign("list",$newarray_1);
					$this->assign('page',$show);// 赋值分页输出
					$this->display();
				}
			}else{
				
				
			
				$shops['apply']=1;
				$shops['isApply']=1;
				$shops['photo1']=array('neq','');
				
				//var_dump($list);exit();
				//where(array('shop_id'=>array('in','2002,1999,1998,1997'))->
				$hot_shop=$shopModel->where($shops)->order('shop_id desc')->limit(3)->select();
				
				$this->assign('hot_shop',$hot_shop);
				
				$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
				$this->assign('guding',$guding);
				
				
				$name = I('get.name');
				$shopModel=M('shop');
				$shop['type']=array('like',"%$name%");
				
				$res = $shopModel->where($shop)->select();
				if($res){
					import('ORG.Util.Page');// 导入分页类
					$count=count($res);//得到数组元素个数
					$Page= new \Think\Page($count,25);
					//$Page= new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
					$newarray_1 = array_slice($res,$Page->firstRow,$Page->listRows);
					$show= $Page->show();// 分页显示输出?
					$name=$_GET['name'];
					$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
					$this->assign('guding',$guding);
					$this->assign('name',$name);
					$this->assign("list",$newarray_1);
					$this->assign('page',$show);// 赋值分页输出
					$this->display();
				}else{
					$type['type']=$name;
					$typeRes = $shopModel->where($type)->select();
					import('ORG.Util.Page');// 导入分页类
					$count=count($typeRes);//得到数组元素个数
					$Page= new \Think\Page($count,25);
					//$Page= new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
					$newarray_1 = array_slice($typeRes,$Page->firstRow,$Page->listRows);
					$show= $Page->show();// 分页显示输出?
					$name=$_GET['name'];
					$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
					$this->assign('guding',$guding);
					$this->assign('name',$name);
					$this->assign("list",$newarray_1);
					$this->assign('page',$show);// 赋值分页输出
					$this->display();
				}
				
				
			}
		}else{
			
			if($_GET['id']){
					$shopModel = M('Shop');
				
					$shops['apply']=1;
					$shops['isApply']=1;
					$shops['photo1']=array('neq','');
					
					//var_dump($list);exit();
					//where(array('shop_id'=>array('in','2002,1999,1998,1997'))->
					$hot_shop=$shopModel->where($shops)->order('shop_id desc')->limit(3)->select();
					
					$this->assign('hot_shop',$hot_shop);
					
					$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
					$this->assign('guding',$guding);
					
					
					
					$shopModel=M('shop');
					
					$shop['name']=array('like',"%$name%");
					$are=M('area')->where(array('area_id'=>$_GET['id']))->find();
					$shop['area']=$are['name'];
					
					$res = $shopModel->where($shop)->select();
				if($res){
					import('ORG.Util.Page');// 导入分页类
					$count=count($res);//得到数组元素个数
					$Page= new \Think\Page($count,25);
					//$Page= new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
					$newarray_1 = array_slice($res,$Page->firstRow,$Page->listRows);
					$show= $Page->show();// 分页显示输出?
					$name=$_GET['name'];
					$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
					$this->assign('guding',$guding);
					$this->assign('name',$name);
					$this->assign("list",$newarray_1);
					$this->assign('page',$show);// 赋值分页输出
					$this->display();
				}else{
					$type['type']=$name;
					$typeRes = $shopModel->where($type)->select();
					import('ORG.Util.Page');// 导入分页类
					$count=count($typeRes);//得到数组元素个数
					$Page= new \Think\Page($count,25);
					//$Page= new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
					$newarray_1 = array_slice($typeRes,$Page->firstRow,$Page->listRows);
					$show= $Page->show();// 分页显示输出?
					$name=$_GET['name'];
					$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
					$this->assign('guding',$guding);
					$this->assign('name',$name);
					$this->assign("list",$newarray_1);
					$this->assign('page',$show);// 赋值分页输出
					$this->display();
				}
				
			}else{
				
					$shopModel = M('Shop');
					$shops['apply']=1;
					$shops['isApply']=1;
					$shops['photo1']=array('neq','');
					
					//var_dump($list);exit();
					//where(array('shop_id'=>array('in','2002,1999,1998,1997'))->
					$hot_shop=$shopModel->where($shops)->order('shop_id desc')->limit(3)->select();
					
					$this->assign('hot_shop',$hot_shop);
					$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
					$this->assign('guding',$guding);
					
					$shopModel=M('shop');
					
					$shop['name']=array('like',"%$name%");
					
					
					$res = $shopModel->where($shop)->select();
					
				if($res){
					import('ORG.Util.Page');// 导入分页类
					$count=count($res);//得到数组元素个数
					$Page= new \Think\Page($count,25);
					//$Page= new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
					$newarray_1 = array_slice($res,$Page->firstRow,$Page->listRows);
					$show= $Page->show();// 分页显示输出?
					$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
					$this->assign('guding',$guding);
					$this->assign('name',$name);
					$this->assign("list",$newarray_1);
					$this->assign('page',$show);// 赋值分页输出
					$this->display();
				}else{
					
					$type['name']=array('like',"%$name%");
					
					$typeRes = $shopModel->where($type)->select();
					import('ORG.Util.Page');// 导入分页类
					$count=count($typeRes);//得到数组元素个数
					$Page= new \Think\Page($count,25);
					//$Page= new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
					$newarray_1 = array_slice($typeRes,$Page->firstRow,$Page->listRows);
					$show= $Page->show();// 分页显示输出?
					$guding=$shopModel->where(array('phone'=>'15512900003'))->find();
			
					$this->assign('guding',$guding);
					$this->assign('name',$name);
					$this->assign("list",$newarray_1);
					$this->assign('page',$show);// 赋值分页输出
					$this->display();
				}
				
				
				
			}
		}
		
		
		
		
		
		
	}
	
}